import 'package:flutter/material.dart';
import 'package:json/json.dart';
import 'package:schedule_self_client/api/schedule_self_server/task_category.dart';
import 'package:schedule_self_client/utils/time_util.dart';

@JsonCodable()
class Task {
  final int id;

  final String name;

  final String? description;

  final String? deadline;

  final int completeFlag;

  final String? completeTime;

  final TaskCategory? taskCategoryDto;

  bool isComplete() {
    return completeFlag == 1;
  }

  String getDescriptionWithDefault() {
    if (description == null || description!.isEmpty) {
      return '暂无描述信息';
    }
    return description!;
  }

  TextStyle? getDeadlineTextStyle() {
    if (deadline == null || deadline!.isEmpty) {
      return null;
    }
    DateTime deadlineTime = DateTime.parse(deadline!);
    if (!TimeUtil.beforeNow(deadlineTime!)) {
      return null;
    }
    return const TextStyle(color: Colors.red);
  }
}
